package vsvm.data.model;

import vsvm.gui.Environment;

public class GenericDataModel extends AbstractDataModel{
	private static final long serialVersionUID = 100L;
	
	
	public int getVectorCount() {
		return features == null ? 0 : features.size(); 
	}
	
	public AbstractAttribute getAttribute(int index) {
		return attributes == null ? null : attributes.get(index);		
	}
	
	public double[] getVector(int index) {
		return features.get(index);				// todo check
	}
	
	public double getClass(int index) {
		return features.get(index)[classIndex];
	}
	
	
	public double[] getAttributeData(AbstractAttribute attr)
	{
		int index;
		for (index = 0; index < getAttributeCount() && !attr.equals(getAttribute(index)); ++index);
		
		if (index >= getAttributeCount()) return null; // TODO throw exception?
		
		int n = features.size();
		double[] data = new double[n];
		
		for (int i = 0; i < n; i++)
			data[i] = features.get(i)[index];
			
		return data;	
	}
	
	public double getValue(int index, int attrIndex) {
		return features.get(index)[attrIndex];
	}
	
	public void setValue(double val, int index, int attrIndex) {
		features.get(index)[attrIndex] = val;
	}
	
	public String getQuickInfo() {
		return "Number of attributes: " + getAttributeCount() + Environment.newline +
		"Number of vectors: " + getVectorCount();
	}
	

}
